home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmille / Source / CardsTracker.m < prev    next >
Text File  |  1991-01-11  |  2KB  |  106 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "CardsTracker.h"
  5. #import    "GameCoordinator.h"
  6. #import    <assert.h>
  7. #import    <libc.h>
  8. #import    <strings.h>
  9.  
  10.  
  11. @implementation CardsTracker
  12.  
  13. - cardPlayed:aCard
  14. {
  15.  
  16.     TextFieldCell    *tCell = [ cardsPlayedMatrix findCellWithTag:[ aCard tag ]];
  17.     char            *dataField = alloca( strlen([ tCell stringValue ]) + 8 );
  18.     
  19.     
  20.     sprintf( dataField, "(%d) %s", ([ self numPlayed:[ aCard tag ]] + 1 ), strstr([ tCell stringValue ], "of" ));
  21.     [ tCell setStringValue:dataField ];
  22.     
  23.     return self;
  24. }
  25.  
  26. - newHand
  27. {
  28.  
  29.     int        i;
  30.     
  31.     
  32.     for( i = 0; cardDeck[ i ].cardClassName; ++i ) {
  33.         char    *fieldData = alloca( 13 + strlen( cardDeck[ i ].cardClassName ) + 8 );
  34.         
  35.         sprintf( fieldData, "(0) of (%d), %s", cardDeck[ i ].numCards, cardDeck[ i ].cardClassName );
  36.         [[ cardsPlayedMatrix findCellWithTag:cardDeck[ i ].cardType ] setStringValue:fieldData ];
  37.     }
  38.     
  39.     return self;
  40. }
  41.  
  42.  
  43. - ( int )numPlayed:( int )aCardTag
  44. {
  45.  
  46.     TextFieldCell    *tCell = [ cardsPlayedMatrix findCellWithTag:aCardTag ];
  47.     int                numPlayed;
  48.     
  49.     
  50.     assert( tCell );
  51.     sscanf([ tCell stringValue ], "(%d)", &numPlayed );
  52.  
  53.     return numPlayed;
  54. }
  55.  
  56.  
  57. - ( int )numInDeck:( int )aCardTag
  58. {
  59.  
  60.     int        i;
  61.     
  62.     
  63.     for( i = 0; cardDeck[ i ].cardClassName; ++i )
  64.         if( aCardTag == cardDeck[ i ].cardType )
  65.             return cardDeck[ i ].numCards;
  66.  
  67.     assert( 0 /* unable to find card in deck */ );
  68.  
  69. }
  70.  
  71.  
  72. - ( BOOL )allPlayed:( int )aCardTag
  73. {
  74.  
  75.  
  76.     return [ self numPlayed:aCardTag ] == [ self numInDeck:aCardTag ];
  77. }
  78.  
  79.  
  80.  
  81. - ( BOOL )allSafetiesPlayed
  82. {
  83.  
  84.     
  85.     return [ self numSafetiesPlayed ] == NUMBER_OF_SAFETY_CARDS_IN_DECK ;
  86. }
  87.  
  88.  
  89. - ( int )numSafetiesPlayed
  90. {
  91.  
  92.     int        cardTypes[] = {    C_RIGHT_OF_WAY_SAFETY, C_PUNCTURE_PROOF_SAFETY, 
  93.                             C_DRIVING_ACE_SAFETY, C_EXTRA_TANK_SAFETY },
  94.             i, cnt;
  95.             
  96.     
  97.     for( i = 0, cnt = 0; i < ( sizeof( cardTypes ) / sizeof( int )); ++i )
  98.         if([ self allPlayed:cardTypes[ i ]])
  99.             ++cnt;
  100.     
  101.     return cnt;
  102. }
  103.  
  104.  
  105. @end
  106.